unit SerinoRapor;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Mask, wwdbedit, StdCtrls, wwdbdatetimepicker, DB, ADODB,
  Buttons, Grids, Wwdbigrd, Wwdbgrid, ppCtrls, ppVar, ppPrnabl, ppClass,
  ppBands, ppCache, ppModule, daDataModule, ppProd, ppReport, ppComm,
  ppRelatv, ppDB, ppDBPipe, TXComp, TXRB;

type
  TSerinoRaporF = class(TForm)
    Label15: TLabel;
    Label14: TLabel;
    basTar: TwwDBDateTimePicker;
    BitTar: TwwDBDateTimePicker;
    FirmaAdik: TwwDBEdit;
    stokkoduk: TwwDBEdit;
    SerinoRapor: TADOQuery;
    SerinoRaporS: TDataSource;
    wwDBGrid1: TwwDBGrid;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    BitBtn3: TBitBtn;
    Label1: TLabel;
    Label2: TLabel;
    ppDBPipeline1: TppDBPipeline;
    SeriNoPrint: TppReport;
    daDataModule1: TdaDataModule;
    ppHeaderBand1: TppHeaderBand;
    ppDetailBand1: TppDetailBand;
    ppFooterBand1: TppFooterBand;
    ppTitleBand1: TppTitleBand;
    ppLabel1: TppLabel;
    ppSystemVariable1: TppSystemVariable;
    ppSystemVariable2: TppSystemVariable;
    ppDBText1: TppDBText;
    ppLabel2: TppLabel;
    ppDBText2: TppDBText;
    ppLabel3: TppLabel;
    ppDBText3: TppDBText;
    ppLabel4: TppLabel;
    ppLine1: TppLine;
    ppLine2: TppLine;
    ppLabel5: TppLabel;
    ppDBCalc1: TppDBCalc;
    ExtraOptions1: TExtraOptions;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure cariara(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure stokkodubul(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure FormShow(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
    procedure BitBtn3Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  SerinoRaporF: TSerinoRaporF;
  stokkod, carikod: integer;

implementation

uses data, cariaral, ucariara2, stokaral, Unit2;

{$R *.dfm}

procedure TSerinoRaporF.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  Action := cafree;
  SerinoRaporF := nil;
end;

procedure TSerinoRaporF.cariara(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var
  t: integer;
begin
  t := TwwDBEdit(sender).Tag;
  if (key = 13) and ((sender as TwwDBEdit).text <> '') then
  begin
    dm.Cariara.Close;
    dm.Cariara.SQL.Clear;
    dm.Cariara.SQL.Add('select distinct carikod, carikodu, istihbarat, Tekyetkili,CTipi=(select adi from dbo.carituru where id=Tipi), FirmaAdi, Soyadi, ilce, Sehir,telefon3 from Cari');

    dm.Cariara.SQL.Add('where (CariKod>0)');
    if t = 1 then
      dm.Cariara.SQL.Add('and (carikodu like ''' + TEdit(sender).text +
        '%'' )');
    if t = 2 then
      dm.Cariara.SQL.Add('and (FirmaAdi like ''' + TEdit(sender).text +
        '%'' )');
    dm.Cariara.Open;
    if (dm.CariAra.RecordCount = 1) then
    begin
      cariKod := dm.cariara.FieldByName('carikod').value;
      //     carikodu.text:=dm.cariara.FieldByName('CariKodu').asstring;
      FirmaAdik.text := dm.cariara.FieldByName('firmaadi').asstring;
    end
    else
    begin
      if (dm.cariAra.RecordCount > 1) then
      begin
        if not assigned(fCariaraL) then
          fCariAraL := tfCariAral.create(self);
        if t = 1 then
        begin
          fCariAraL.siras := 'carikodu';
          fCariAraL.aranan := TEdit(sender).text;
        end;
        if t = 2 then
        begin
          fCariAraL.siras := 'FirmaAdi';
          fCariAraL.aranan := TEdit(sender).text;
        end;

        if fCariAraL.showmodal = mrOk then
        begin
          cariKod := dm.cariara.FieldByName('carikod').value;
          //     carikodu.text:=dm.cariara.FieldByName('CariKodu').asstring;
          FirmaAdik.text := dm.cariara.FieldByName('firmaadi').asstring;
        end
        else
        begin
          fCariAra2 := tfCariAra2.create(self);
          if t = 1 then
            fCariAra2.edit3.Text := TEdit(sender).text;
          if t = 2 then
            fCariAra2.edit4.Text := TEdit(sender).text;
          if fCariAra2.showmodal = mrok then
          begin
            if dm.CariAra.Active = true then
            begin
              cariKod := dm.cariara.FieldByName('carikod').value;
              //     carikodu.text:=dm.cariara.FieldByName('CariKodu').asstring;
              FirmaAdik.text := dm.cariara.FieldByName('firmaadi').asstring;
            end;
          end;
        end;
      end
      else
      begin
        fCariAra2 := tfCariAra2.create(self);
        if t = 1 then
          fCariAra2.edit3.Text := TEdit(sender).text;
        if t = 2 then
          fCariAra2.edit4.Text := TEdit(sender).text;
        fCariAra2.gelis := t;
        if fCariAra2.showmodal = mrok then
        begin
          if dm.CariAra.Active = true then
          begin
            cariKod := dm.cariara.FieldByName('carikod').value;
            //     carikodu.text:=dm.cariara.FieldByName('CariKodu').asstring;
            FirmaAdik.text := dm.cariara.FieldByName('firmaadi').asstring;
          end;
        end;
      end;
    end;
  end;

end;

procedure TSerinoRaporF.stokkodubul(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var
  t: integer;
begin
  t := TEdit(sender).Tag;
  if (key = 13) and (TEdit(sender).text <> '') then
  begin
    dm.stokara.Close;
    dm.stokara.SQL.Clear;
    dm.stokara.SQL.Add(dm.StokilkSql);
    dm.stokara.SQL.Add('where (stok.stokkod>0) ');
    if t = 1 then
      dm.stokara.SQL.Add('and stokkodu like ''' + TEdit(sender).text + '%''');
    if t = 2 then
      dm.stokara.SQL.Add('and cinsi like ''' + TEdit(sender).text + '%''');
    dm.stokara.Open;

    if (dm.stokara.RecordCount = 1) then
    begin
      stokkod := dm.stokara.Fieldbyname('stokkod').asInteger;
      stokkoduk.text := dm.stokara.Fieldbyname('Cinsi').asString;
    end
    else
    begin
      if (dm.stokara.RecordCount > 1) then
      begin
        if not assigned(fStokaral) then
          fStokaral := tfStokaral.create(self);

        if fstokaral.showmodal = mrOk then
        begin
          stokkod := dm.stokara.Fieldbyname('stokkod').asInteger;
          stokkoduk.text := dm.stokara.Fieldbyname('Cinsi').asString;
        end
        else
        begin
          fstokara2 := tfstokara2.create(self);
          if t = 1 then
            fstokara2.edit3.Text := TEdit(sender).text;
          if t = 2 then
            fstokara2.edit4.Text := TEdit(sender).text;
          if fstokara2.showmodal = mrok then
          begin
            if dm.stokara.Active = true then
            begin
              stokkod := dm.stokara.Fieldbyname('stokkod').asInteger;
              stokkoduk.text := dm.stokara.Fieldbyname('Cinsi').asString;
            end;
          end;
        end;
      end
      else
      begin
        fstokara2 := tfstokara2.create(self);
        if t = 1 then
          fstokara2.edit3.Text := TEdit(sender).text;
        if t = 2 then
          fstokara2.edit4.Text := TEdit(sender).text;
        fstokara2.gelis := t;
        if fstokara2.showmodal = mrok then
        begin
          if dm.stokara.Active = true then
          begin
            stokkod := dm.stokara.Fieldbyname('stokkod').asInteger;
            stokkoduk.text := dm.stokara.Fieldbyname('Cinsi').asString;
          end;
        end;
      end;
    end;
  end;

end;

procedure TSerinoRaporF.FormShow(Sender: TObject);
begin
  basTar.Date := SadeceTarih - 30;
  bitTar.Date := SadeceTarih;
end;

procedure TSerinoRaporF.BitBtn1Click(Sender: TObject);
begin

  SerinoRapor.Close;
  SerinoRapor.SQL.Clear;
  SerinoRapor.SQL.Add('select serinos,stokkodu=(select stokkodu from stok where stok.stokkod=fatharhar.stokkod),carikodu=(select carikodu from cari where cari.carikod=fatura.carikod) from fatura,fatharhar where (fatura.bilisno=fatharhar.bilisnocik) ');
  SerinoRapor.SQL.Add('and (fatura.tarih>:bastar) and (fatura.tarih<:bittar)');

  if (carikod > 0) and (trim(firmaadik.text) <> '') then
    SerinoRapor.SQL.Add('and (fatura.Carikod=' + inttostr(carikod) + ')');
  if (stokkod > 0) and (trim(stokkoduk.text) <> '') then
    SerinoRapor.SQL.Add('and (fatharhar.Stokkod=' + inttostr(stokkod) + ')');

  SerinoRapor.Parameters.ParamByName('BasTar').datatype := ftDate;
  SerinoRapor.Parameters.ParamByName('BitTar').datatype := ftDate;
  SerinoRapor.Parameters.ParamByName('BasTar').value := BasTar.date;
  SerinoRapor.Parameters.ParamByName('BitTar').value := BitTar.date + 1;

  //  memo1.clear;
  //  memo1.Lines.AddStrings(SerinoRapor.SQL);
  SerinoRapor.Open;

  Caption := '(Seri No Raporu - ' + inttostr(SerinoRapor.recordcount) +
    ' Adet)';
  wwDBGrid1.SetFocus;

end;

procedure TSerinoRaporF.BitBtn2Click(Sender: TObject);
begin
  SeriNoPrint.Print;
end;

procedure TSerinoRaporF.BitBtn3Click(Sender: TObject);
begin
  close;
end;

end.

